package com.tron.dobest.java.trondesign.observer;

import java.util.ArrayList;

public class TronSubject implements Subject {
    private ArrayList<Observer> observers = new ArrayList<>();
    private String a;
    private String b;

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.forEach(e->{
            if (e.equals(observer)) {
                observers.remove(observer);
            }
        });
    }

    @Override
    public void notifyObservers() {
        observers.forEach(e->{
            e.update(a,b);
        });
    }

    public void change(String a, String b) {
        this.a = a;
        this.b = b;
        notifyObservers();
    }
}
